#include<stdio.h>
#include<stdlib.h>
#include<filesystem>
using namespace std;
typedef struct teacher{
    char name[10];
    char sex;
    int age;
    struct teacher *next;
}*t;
t create_st(t st,int n){
    t head=NULL;
    if(st==NULL){
        st=(t)malloc(sizeof(struct teacher));
        head=st;
        st->next=NULL;
    }
        
    for(int i=0;i<n;i++){
        t node=(t)malloc(sizeof(struct teacher));
        scanf("%s %c %d",&node->name,&node->sex,&node->age);
        node->next=NULL;
        //尾插法
        st->next=node;
        st=st->next;
        //头插法
        // node->next=head->next;
        // head->next=node;
    }
    return head;
}
void output(t head){
    t p=head->next;
    while(p){
        printf("%s\t%c\t%d\n",p->name,p->sex,p->age);
        p=p->next;
    }
}
void save_female(t head){
    t p=head->next;
    // t qhead=(t)malloc(sizeof(struct teacher));
    // while(p){
    //     if(p->sex=='0'){
    //         if(qhead->next=NULL){//头插法
    //             p->next=qhead->next;
    //             qhead->next=p;
    //         }else{
    //             p->next=qhead->next;
    //             qhead->next=p;
    //         }
    //     }
    //     p=p->next;
    // }
    FILE *fw=fopen("./output.txt","wb");
    if(fw==NULL){
        printf("error!");
    }
    while(p){
        if(p->sex=='0'){
            fprintf(fw,"%5s",p->name);
            fprintf(fw,"%5c",p->sex);
            fprintf(fw,"%5d\n",p->age);
        }
        p=p->next;
    }
    fclose(fw);
    // return qhead;
}
int main(){
    t st=NULL;
    st=create_st(st,2);
    output(st);
    save_female(st);
    return 0;
}